<?php

namespace app\controller;

use App\Api\PrinterService;
use App\Api\PrintService;
use app\BaseController;
use App\Config\YlyConfig;
use App\Oauth\YlyOauthClient;
use think\facade\Cache;
use think\helper\Str;

class Test extends BaseController
{
    public function index()
    {
        $conf = new YlyConfig("1061758456", "e4b0a55c48c6c296d7f0469954803667");
        $conf->setRequestUrl("https://open-api.10ss.net/v2");
        if (!Cache::has("yly_print_access_token")) {
            $data = (new YlyOauthClient($conf));
            $token = $data->getToken();
            Cache::set("yly_print_access_token", $token, 48 * 3600 * 24);
        } else {
            $token = Cache::get("yly_print_access_token");
        }
        //{#161 ▼
        //  +"error": 0
        //  +"error_description": "success"
        //  +"timestamp": 1755755242
        //  +"body": {#162 ▼
        //    +"id": 3551480851
        //    +"origin_id": "20250821134721792513"
        //  }
        //}
//        $print = new YlyPrintClient($token->access_token, $conf);
        $print = new PrintService($token->access_token, $conf);
        $content = str_repeat('.', 32)."\n";
        $content .= "站点：SF-测试加油站\n流水：".setOrderSn()."\n时间：".date("m月d H:i:s");
        $content .= "\n".str_repeat('.', 32)."\n";
        $content .= "<FS>油枪：2号枪</FS>\n<FS>油品：92#</FS>\n<FS>升数：43.1</FS>\n实际加油升数以油站加油机为准!\n";
        $content .= str_repeat('.', 32)."\n";
        $content .="<FS2>加油金额</FS2>\n<FS2>￥120.00元</FS2>\n";
        $content .= str_repeat('.', 14)." SF ".str_repeat('.', 14);
        $dd = $print->index('4004891902',$content,date("YmdHis").Str::random(6,1));
        dd($dd);
//        $bind = (new PrinterService($token->access_token,$conf));
//        dd($bind);
//        $bid = $bind->addPrinter("4004891902","752802470618");
//        dd($bid);
//        dd($token);
//        dd(json_decode(json_encode($data->getToken()),true));
//        https://open-api.10ss.net/oauth/authorize?client_id=xxxx&response_type=code&state=aaa&redirect_uri=https://xxxx
//       header("location://open-api.10ss.net/oauth/authorize?client_id=".$conf->getClientId()."&response_type=code&state=types&redirect_uri=https://gas-test.zhissf.com/api/print");
//        dd($conf);
    }
}
